home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / IISWEB.VB_ / iisweb.vbs
Encoding:
Text File  |  2003-02-21  |  47.8 KB  |  1,254 lines

  1. '
  2. ' Copyright (c) Microsoft Corporation.  All rights reserved.
  3. '
  4. ' VBScript Source File 
  5. '
  6. ' Script Name: IIsWeb.vbs
  7. '
  8.  
  9. Option Explicit
  10. On Error Resume Next
  11.  
  12. ' Error codes
  13. Const ERR_OK                         = 0
  14. Const ERR_GENERAL_FAILURE            = 1
  15.  
  16. '''''''''''''''''''''
  17. ' Messages
  18. Const L_BindingConflict_ErrorMessage = "(ERROR: BINDING CONFLICT)"
  19. Const L_SitesNotFound_ErrorMessage  = "Site(s) not found."
  20. Const L_IsAlready_Message       = "Server %1 is already %2"
  21. Const L_CannotStart_Message     = "%1: Server cannot be started in its current state"
  22. Const L_CannotStart2_Message    = "(%1 server is %2)"
  23. Const L_CannotStop_Message      = "%1: Server cannot be stopped in its current state"
  24. Const L_CannotStop2_Message     = "(%1 server is %2)"
  25. Const L_CannotPause_Message     = "%1: Server cannot be paused in its current state"
  26. Const L_CannotPause2_Message    = "(%1 server is %2)"
  27. Const L_HasBeen_Message         = "Server %1 has been %2"
  28.  
  29. Const L_All_Text                = "ALL"
  30. Const L_AllUnassigned_Text      = "ALL UNASSIGNED"
  31. Const L_NotSpecified_Text       = "NOT SPECIFIED"
  32.  
  33. Const L_Server_Text          = "Server"
  34. Const L_SiteName_Text        = "Site Name"
  35. Const L_MetabasePath_Message = "Metabase Path"
  36. Const L_IP_Text              = "IP"
  37. Const L_Host_Text            = "Host"
  38. Const L_Port_Text            = "Port"
  39. Const L_Root_Text            = "Root"
  40. Const L_Status_Text          = "Status"
  41. Const L_NA_Text              = "N/A"
  42.  
  43. Const L_Error_ErrorMessage             = "Error &H%1: %2"
  44. Const L_UnexpectedState_ErrorMessage   = "Unexpected state"
  45. Const L_GetRoot_ErrorMessage           = "Could not obtaing ROOT virtual dir of site %1"
  46. Const L_RecursiveDel_ErrorMessage      = "Could not recursively delete application site %1"
  47. Const L_SiteGet_ErrorMessage           = "Could not obtain web site %1"
  48. Const L_Stop_ErrorMessage              = "Could not stop web site %1"
  49. Const L_SiteDel_ErrorMessage           = "Could not delete web site %1"
  50. Const L_GetWebServer_ErrorMessage      = "Error trying to obtain WebServer object."
  51. Const L_CannotCreateDir_ErrorMessage   = "Could not create root directory"
  52. Const L_DirFormat_ErrorMessage         = "Root directory format unknown. Please use the"
  53. Const L_DirFormat2_ErrorMessage        = "'<drive>:\<path>' format."
  54. Const L_CannotControl_ErrorMessage     = "Server cannot be controled in its current state"
  55. Const L_FailChange_ErrorMessage        = "Failed to change status of server %1"
  56. Const L_OperationRequired_ErrorMessage = "Please specify an operation before the arguments."
  57. Const L_MinInfoNeeded_ErrorMessage     = "Need at least <root> to create a site."
  58. Const L_NotEnoughParams_ErrorMessage   = "Not enough parameters."
  59. Const L_Query_ErrorMessage             = "Error occurred while querying WMI provider."
  60. Const L_OnlyOneOper_ErrorMessage       = "Please specify only one operation at a time."
  61. Const L_ServerInstance_ErrorMessage    = "Error trying to create a new web server instance."
  62. Const L_ServerPut_ErrorMessage         = "Error trying to save new web server instance."
  63. Const L_VDirInstance_ErrorMessage      = "Error trying to create a new virtual directory instance."
  64. Const L_VDirPut_ErrorMessage           = "Error trying to save new virtual directory instance."
  65. Const L_ScriptHelper_ErrorMessage      = "Could not create an instance of the IIsScriptHelper object."
  66. Const L_CmdLib_ErrorMessage            = "Could not create an instance of the CmdLib object."
  67. Const L_ChkCmdLibReg_ErrorMessage      = "Please register the Microsoft.CmdLib component."
  68. Const L_ChkScpHelperReg_ErrorMessage   = "Please register the Microsoft.IIsScriptHelper component."
  69. Const L_InvalidIP_ErrorMessage         = "Invalid IP Address. Please check if it is well formated and"
  70. Const L_InvalidIP2_ErrorMessage        = "belongs to this machine."
  71. Const L_InvalidPort_ErrorMessage       = "Invalid port number."
  72. Const L_MapDrive_ErrorMessage          = "Could not map network drive."
  73. Const L_PassWithoutUser_ErrorMessage   = "Please specify /u switch before using /p."
  74. Const L_WMIConnect_ErrorMessage        = "Could not connect to WMI provider."
  75. Const L_InvalidSwitch_ErrorMessage     = "Invalid switch: %1"
  76. Const L_Admin_ErrorMessage             = "You cannot run this command because you are not an"
  77. Const L_Admin2_ErrorMessage            = "administrator on the server you are trying to configure."
  78.  
  79. '''''''''''''''''''''
  80. ' Help
  81.  
  82. ' General help messages
  83. Const L_SeeHelp_Message       = "Type IIsWeb /? for help."
  84. Const L_SeeStartHelp_Message  = "Type IIsWeb /start /? for help."
  85. Const L_SeeStopHelp_Message   = "Type IIsWeb /stop /? for help."
  86. Const L_SeePauseHelp_Message  = "Type IIsWeb /pause /? for help."
  87. Const L_SeeCreateHelp_Message = "Type IIsWeb /create /? for help."
  88. Const L_SeeDeleteHelp_Message = "Type IIsWeb /delete /? for help."
  89. Const L_SeeQueryHelp_Message  = "Type IIsWeb /query /? for help."
  90.  
  91.  
  92. Const L_Help_HELP_General01_Text  = "Description: Start, Stop, Pause, Delete, Query, or Create a"
  93. Const L_Help_HELP_General01a_Text = "             Web Site"
  94. Const L_Help_HELP_General02_Text  = "Syntax: IIsWeb [/s <server> [/u <username> [/p <password>]]]"
  95. Const L_Help_HELP_General03_Text  = "        /<operation> [arguments]"
  96. Const L_Help_HELP_General04_Text  = "Parameters:"
  97. Const L_Help_HELP_General05_Text  = ""
  98. Const L_Help_HELP_General06_Text  = "Value                   Description"
  99. Const L_Help_HELP_General07_Text  = "/s <server>             Connect to machine <server>"
  100. Const L_Help_HELP_General07a_Text = "                        [Default: this system]"
  101. Const L_Help_HELP_General08_Text  = "/u <username>           Connect as <domain>\<username> or"
  102. Const L_Help_HELP_General09_Text  = "                        <username> [Default: current user]"
  103. Const L_Help_HELP_General10_Text  = "/p <password>           Password for the <username> user"
  104. Const L_Help_HELP_General11_Text  = "<operation>             /start   Starts a site(s) on given"
  105. Const L_Help_HELP_General11a_Text = "                                 IIS Server."
  106. Const L_Help_HELP_General12_Text  = "                        /stop    Stops a site(s) from running"
  107. Const L_Help_HELP_General13_Text  = "                                 on a given IIS Server."
  108. Const L_Help_HELP_General14_Text  = "                        /pause   Pauses a site(s) that is"
  109. Const L_Help_HELP_General15_Text  = "                                 running on a given IIS Server."
  110. Const L_Help_HELP_General18_Text  = "                        /delete  Deletes IIS configuration"
  111. Const L_Help_HELP_General19_Text  = "                                 from an existing Web Site."
  112. Const L_Help_HELP_General19a_Text = "                                 Content will not be deleted."
  113. Const L_Help_HELP_General20_Text  = "                        /create  Creates a Web Site."
  114. Const L_Help_HELP_General21_Text  = "                        /query   Queries existing Web Sites."
  115. Const L_Help_HELP_General22_Text  = "For detailed usage:"
  116. Const L_Help_HELP_General23_Text  = "IIsWeb /start /?"
  117. Const L_Help_HELP_General24_Text  = "IIsWeb /stop /?"
  118. Const L_Help_HELP_General25_Text  = "IIsWeb /pause /?"
  119. Const L_Help_HELP_General27_Text  = "IIsWeb /delete /?"
  120. Const L_Help_HELP_General28_Text  = "IIsWeb /create /?"
  121. Const L_Help_HELP_General29_Text  = "IIsWeb /query /?"
  122.  
  123. ' Common to all status change commands
  124. Const L_Help_HELP_Status03_Text   = "Parameters:"
  125. Const L_Help_HELP_Status09_Text   = "<website>               Use either the site name or metabase"
  126. Const L_Help_HELP_Status09p1_Text = "                        path to specify the site"
  127. Const L_Help_HELP_Status10_Text   = "Examples:"
  128.  
  129. ' Start help messages
  130. Const L_Help_HELP_Start01_Text   = "Description: Starts a site(s) on a given IIS Server."
  131. Const L_Help_HELP_Start02_Text   = "Syntax: IIsWeb [/s <server> [/u <username> [/p <password>]]]"
  132. Const L_Help_HELP_Start02p1_Text = "        /start <website> [<website> ...]"
  133. Const L_Help_HELP_Start11_Text   = "IIsWeb /start ""Default Web Site"""
  134. Const L_Help_HELP_Start12_Text   = "IIsWeb /start w3svc/1"
  135. Const L_Help_HELP_Start13_Text   = "IIsWeb /start w3svc/2 ""Default Web Site"" w3svc/10"
  136. Const L_Help_HELP_Start14_Text   = "IIsWeb /s Server1 /u Administrator /p p@ssWOrd /start w3svc/4"
  137.  
  138. ' Stop help messages
  139. Const L_Help_HELP_Stop01_Text   = "Description: Stops a site(s) on a given IIS Server."
  140. Const L_Help_HELP_Stop02_Text   = "Syntax: IIsWeb [/s <server> [/u <username> [/p <password>]]]"
  141. Const L_Help_HELP_Stop02p1_Text = "        /stop <website> [<website> ...]"
  142. Const L_Help_HELP_Stop11_Text   = "IIsWeb /stop ""Default Web Site"""
  143. Const L_Help_HELP_Stop12_Text   = "IIsWeb /stop w3svc/1"
  144. Const L_Help_HELP_Stop13_Text   = "IIsWeb /stop w3svc/2 ""Default Web Site"" w3svc/10"
  145. Const L_Help_HELP_Stop14_Text   = "IIsWeb /s Server1 /u Administrator /p p@ssWOrd /stop w3svc/4"
  146.  
  147. ' Pause help messages
  148. Const L_Help_HELP_Pause01_Text   = "Description: Pauses a site(s) on a given IIS Server."
  149. Const L_Help_HELP_Pause02_Text   = "Syntax: IIsWeb [/s <server> [/u <username> [/p <password>]]]"
  150. Const L_Help_HELP_Pause02p1_Text = "        /pause <website> [<website> ...]"
  151. Const L_Help_HELP_Pause11_Text   = "IIsWeb /pause ""Default Web Site"""
  152. Const L_Help_HELP_Pause12_Text   = "IIsWeb /pause w3svc/1"
  153. Const L_Help_HELP_Pause13_Text   = "IIsWeb /pause w3svc/2 ""Default Web Site"" w3svc/10"
  154. Const L_Help_HELP_Pause14_Text   = "IIsWeb /s Server1 /u Administrator /p p@ssWOrd /pause w3svc/4"
  155.  
  156. ' Delete help messages
  157. Const L_Help_HELP_Delete01_Text   = "Description: Deletes IIS configuration for an existing web"
  158. Const L_Help_HELP_Delete01p1_Text = "             site. Content will not be deleted."
  159. Const L_Help_HELP_Delete02_Text   = "Syntax: IIsWeb [/s <server> [/u <username> [/p <password>]]]"
  160. Const L_Help_HELP_Delete02p1_Text = "        /delete <website> [<website> ...]"
  161. Const L_Help_HELP_Delete11_Text   = "IIsWeb /delete ""Default Web Site"""
  162. Const L_Help_HELP_Delete12_Text   = "IIsWeb /delete w3svc/1"
  163. Const L_Help_HELP_Delete13_Text   = "IIsWeb /delete w3svc/2 ""Default Web Site"" w3svc/10"
  164. Const L_Help_HELP_Delete14_Text   = "IIsWeb /s Server1 /u Administrator /p p@ssWOrd /delete w3svc/4"
  165.  
  166. ' Create help messages
  167. Const L_Help_HELP_Create01_Text   = "Description: Creates a web site."
  168. Const L_Help_HELP_Create02_Text   = "Syntax: IIsWeb [/s <server> [/u <username> [/p <password>]]]"
  169. Const L_Help_HELP_Create02p1_Text = "        /create <root> <name> [/d <host>] [/b <port>]"
  170. Const L_Help_HELP_Create02p2_Text = "        [/i <ip>] [/dontstart]"
  171. Const L_Help_HELP_Create09_Text   = "<root>                  Root directory for the new server. If"
  172. Const L_Help_HELP_Create09p1_Text = "                        this directory does not exist, it"
  173. Const L_Help_HELP_Create09p2_Text = "                        will be created."
  174. Const L_Help_HELP_Create10_Text   = "<name>                  The name that appears in the Microsoft"
  175. Const L_Help_HELP_Create10p1_Text = "                        Management Console (MMC)."
  176. Const L_Help_HELP_Create11_Text   = "/d <host>               The host name to assign to this site."
  177. Const L_Help_HELP_Create11p1_Text = "                        WARNING: Only use host name if DNS"
  178. Const L_Help_HELP_Create11p2_Text = "                        is set up to find the server"
  179. Const L_Help_HELP_Create12_Text   = "/b <port>               The number of the port to which the"
  180. Const L_Help_HELP_Create12p1_Text = "                        new server should bind. [Default: 80]"
  181. Const L_Help_HELP_Create13_Text   = "/i <ip>                 The IP address to assign to the new"
  182. Const L_Help_HELP_Create13p1_Text = "                        server. [Default: All Unassigned]"
  183. Const L_Help_HELP_Create15_Text   = "/dontstart              Don't start this site after it is created."
  184. Const L_Help_HELP_Create22_Text   = "IIsWeb /create c:\inetpub\wwwroot ""My Site"" /b 80"
  185. Const L_Help_HELP_Create23_Text   = "IIsWeb /s Server1 /u Administrator /p p@assWOrd /create c:\inetpub\wwwroot"
  186. Const L_Help_HELP_Create23p1_Text = "       ""My Site"""
  187. Const L_Help_HELP_Create24_Text   = "IIsWeb /create c:\inetpub\wwwroot ""My Site"" /i 172.30.163.244 /b 80"
  188. Const L_Help_HELP_Create24p1_Text = "       /d www.mysite.com"
  189.  
  190. ' Query help messages
  191. Const L_Help_HELP_Query01_Text   = "Description: Queries existing web sites."
  192. Const L_Help_HELP_Query02_Text   = "Syntax: IIsWeb [/s <server> [/u <username> [/p <password>]]]"
  193. Const L_Help_HELP_Query02p1_Text = "        /query [<website> ...]"
  194. Const L_Help_HELP_Query11_Text   = "IIsWeb /query ""Default Web Site"""
  195. Const L_Help_HELP_Query12_Text   = "IIsWeb /query w3svc/1"
  196. Const L_Help_HELP_Query13_Text   = "IIsWeb /query"
  197. Const L_Help_HELP_Query14_Text   = "IIsWeb /query ""Default Web Site"" ""Sample Site"" w3svc/1"
  198. Const L_Help_HELP_Query15_Text   = "IIsWeb /s Server1 /u Administrator /p p@ssW0rd /query ""Default Web Site"""
  199.  
  200. ' Status
  201. Const L_Started_Text   = "started"
  202. Const L_Stopped_Text   = "stopped"
  203. Const L_Paused_Text    = "paused"
  204. Const L_Continued_Text = "continued"
  205. Const L_Deleted_Text   = "deleted"
  206.  
  207. ''''''''''''''''''''''''
  208. Dim SiteStatus
  209. SiteStatus = Array("", "", L_Started_Text, "", L_Stopped_Text, "", L_Paused_Text, L_Continued_Text, L_Deleted_Text)
  210.  
  211. ' Operation codes
  212. Const OPER_START    = 1
  213. Const OPER_STOP     = 2
  214. Const OPER_PAUSE    = 3
  215. Const OPER_DELETE   = 4
  216. Const OPER_CREATE   = 5
  217. Const OPER_QUERY    = 6
  218.  
  219. ' ServerState codes
  220. Const SERVER_STARTING   = 1
  221. Const SERVER_STARTED    = 2
  222. Const SERVER_STOPPING   = 3
  223. Const SERVER_STOPPED    = 4
  224. Const SERVER_PAUSING    = 5
  225. Const SERVER_PAUSED     = 6
  226. Const SERVER_CONTINUING = 7
  227.  
  228. '
  229. ' Main block
  230. '
  231. Dim oScriptHelper, oCmdLib
  232. Dim strServer, strUser, strPassword, strSite
  233. Dim intOperation, intResult
  234. Dim strRoot, strName, strHost, strPort, strIP
  235. Dim bDontStart
  236. Dim aArgs, arg
  237. Dim strCmdLineOptions
  238. Dim oError
  239.  
  240. ' Default values
  241. strServer = "."
  242. strUser = ""
  243. strPassword = ""
  244. intOperation = 0
  245. strSite = ""
  246. strName = ""
  247. bDontStart = False
  248.  
  249. ' Instantiate the CmdLib for output string formatting
  250. Set oCmdLib = CreateObject("Microsoft.CmdLib")
  251. If Err.Number <> 0 Then
  252.     WScript.Echo L_CmdLib_ErrorMessage
  253.     WScript.Echo L_ChkCmdLibReg_ErrorMessage    
  254.     WScript.Quit(ERR_GENERAL_FAILURE)
  255. End If
  256. Set oCmdLib.ScriptingHost = WScript.Application
  257.  
  258. ' Instantiate script helper object
  259. Set oScriptHelper = CreateObject("Microsoft.IIsScriptHelper")
  260. If Err.Number <> 0 Then
  261.     WScript.Echo L_ScriptHelper_ErrorMessage
  262.     WScript.Echo L_ChkScpHelperReg_ErrorMessage    
  263.     WScript.Quit(ERR_GENERAL_FAILURE)
  264. End If
  265.  
  266. Set oScriptHelper.ScriptHost = WScript
  267.  
  268. ' Check if we are being run with cscript.exe instead of wscript.exe
  269. oScriptHelper.CheckScriptEngine
  270.  
  271. ' Minimum number of parameters must exist
  272. If WScript.Arguments.Count < 1 Then
  273.     WScript.Echo L_NotEnoughParams_ErrorMessage
  274.     WScript.Echo L_SeeHelp_Message
  275.     WScript.Quit(ERR_GENERAL_FAILURE)
  276. End If
  277.  
  278. strCmdLineOptions = "[server:s:1;user:u:1;password:p:1];start::n;stop::n;pause::n;delete::n;" & _
  279.                     "[create:c:1;domain:d:1;port:b:1;ip:i:1;dontstart::0];query:q:n"
  280. Set oError = oScriptHelper.ParseCmdLineOptions(strCmdLineOptions)
  281.  
  282. If Not oError Is Nothing Then
  283.     If oError.ErrorCode = oScriptHelper.ERROR_NOT_ENOUGH_ARGS Then
  284.         ' Not enough arguments for a specified switch
  285.         WScript.Echo L_NotEnoughParams_ErrorMessage
  286.         If oError.SwitchName = "create" Then
  287.             WScript.Echo L_SeeCreateHelp_Message
  288.         Else
  289.                WScript.Echo L_SeeHelp_Message
  290.         End If
  291.     Else
  292.         ' Invalid switch
  293.         oCmdLib.vbPrintf L_InvalidSwitch_ErrorMessage, Array(oError.SwitchName)
  294.           WScript.Echo L_SeeHelp_Message
  295.     End If
  296.         
  297.         WScript.Quit(ERR_GENERAL_FAILURE)
  298. End If
  299.  
  300. If oScriptHelper.GlobalHelpRequested Then
  301.     DisplayHelpMessage
  302.     WScript.Quit(ERR_OK)
  303. End If
  304.  
  305. For Each arg In oScriptHelper.Switches
  306.     Select Case arg
  307.         Case "server"
  308.             ' Server information
  309.             strServer = oScriptHelper.GetSwitch(arg)
  310.  
  311.         Case "user"
  312.             ' User information
  313.             strUser = oScriptHelper.GetSwitch(arg)
  314.  
  315.         Case "password"
  316.             ' Password information
  317.             strPassword = oScriptHelper.GetSwitch(arg)
  318.         
  319.         Case "start"
  320.             If (intOperation <> 0) Then
  321.                 WScript.Echo L_OnlyOneOper_ErrorMessage
  322.                 WScript.Echo L_SeeHelp_Message
  323.                 WScript.Quit(ERR_GENERAL_FAILURE)
  324.             End If
  325.  
  326.             intOperation = OPER_START
  327.             
  328.                If oScriptHelper.IsHelpRequested(arg) Then
  329.                 DisplayStartHelpMessage
  330.                 WScript.Quit(ERR_OK)
  331.             End If
  332.  
  333.             aArgs = oScriptHelper.GetSwitch(arg)
  334.  
  335.             If UBound(aArgs) = -1 Then
  336.                 WScript.Echo L_NotEnoughParams_ErrorMessage
  337.                 WScript.Echo L_SeeStartHelp_Message
  338.                 WScript.Quit(ERR_GENERAL_FAILURE)
  339.             End If
  340.  
  341.         Case "stop"
  342.             If (intOperation <> 0) Then
  343.                 WScript.Echo L_OnlyOneOper_ErrorMessage
  344.                 WScript.Echo L_SeeHelp_Message
  345.                 WScript.Quit(ERR_GENERAL_FAILURE)
  346.             End If
  347.  
  348.             intOperation = OPER_STOP
  349.             
  350.                If oScriptHelper.IsHelpRequested(arg) Then
  351.                 DisplayStopHelpMessage
  352.                 WScript.Quit(ERR_OK)
  353.             End If
  354.  
  355.             aArgs = oScriptHelper.GetSwitch(arg)
  356.         
  357.             If UBound(aArgs) = -1 Then
  358.                 WScript.Echo L_NotEnoughParams_ErrorMessage
  359.                 WScript.Echo L_SeeStopHelp_Message
  360.                 WScript.Quit(ERR_GENERAL_FAILURE)
  361.             End If
  362.  
  363.         Case "pause"
  364.             If (intOperation <> 0) Then
  365.                 WScript.Echo L_OnlyOneOper_ErrorMessage
  366.                 WScript.Echo L_SeeHelp_Message
  367.                 WScript.Quit(ERR_GENERAL_FAILURE)
  368.             End If
  369.  
  370.             intOperation = OPER_PAUSE
  371.                         
  372.                If oScriptHelper.IsHelpRequested(arg) Then
  373.                 DisplayPauseHelpMessage
  374.                 WScript.Quit(ERR_OK)
  375.             End If
  376.  
  377.             aArgs = oScriptHelper.GetSwitch(arg)
  378.         
  379.             If UBound(aArgs) = -1 Then
  380.                 WScript.Echo L_NotEnoughParams_ErrorMessage
  381.                 WScript.Echo L_SeePauseHelp_Message
  382.                 WScript.Quit(ERR_GENERAL_FAILURE)
  383.             End If
  384.  
  385.         Case "create"
  386.             If (intOperation <> 0) Then
  387.                 WScript.Echo L_OnlyOneOper_ErrorMessage
  388.                 WScript.Echo L_SeeHelp_Message
  389.                 WScript.Quit(ERR_GENERAL_FAILURE)
  390.             End If
  391.  
  392.             intOperation = OPER_CREATE
  393.  
  394.                If oScriptHelper.IsHelpRequested(arg) Then
  395.                 DisplayCreateHelpMessage
  396.                 WScript.Quit(ERR_OK)
  397.             End If
  398.  
  399.             strRoot = oScriptHelper.GetSwitch(arg)
  400.             aArgs = oScriptHelper.NamedArguments
  401.  
  402.             If strRoot = "" Or UBound(aArgs) = -1 Then
  403.                 WScript.Echo L_NotEnoughParams_ErrorMessage
  404.                 WScript.Echo L_SeeCreateHelp_Message
  405.                 WScript.Quit(ERR_GENERAL_FAILURE)
  406.             End If
  407.  
  408.             strName    = aArgs(0)
  409.             strHost    = oScriptHelper.GetSwitch("domain")
  410.             strPort    = oScriptHelper.GetSwitch("port")
  411.             strIP      = oScriptHelper.GetSwitch("ip")
  412.             If oScriptHelper.Switches.Exists("dontstart") Then
  413.                 bDontStart = True
  414.             End If
  415.         
  416.         Case "delete"
  417.             If (intOperation <> 0) Then
  418.                 WScript.Echo L_OnlyOneOper_ErrorMessage
  419.                 WScript.Echo L_SeeHelp_Message
  420.                 WScript.Quit(ERR_GENERAL_FAILURE)
  421.             End If
  422.         
  423.             intOperation = OPER_DELETE
  424.  
  425.             If oScriptHelper.IsHelpRequested(arg) Then
  426.                 DisplayDeleteHelpMessage
  427.                 WScript.Quit(ERR_OK)
  428.             End If
  429.  
  430.             aArgs = oScriptHelper.GetSwitch(arg)
  431.             
  432.             If UBound(aArgs) = -1 Then
  433.                 WScript.Echo L_NotEnoughParams_ErrorMessage
  434.                 WScript.Echo L_SeeDeleteHelp_Message
  435.                 WScript.Quit(ERR_GENERAL_FAILURE)
  436.             End If
  437.         
  438.         Case "query"
  439.             If (intOperation <> 0) Then
  440.                 WScript.Echo L_OnlyOneOper_ErrorMessage
  441.                 WScript.Echo L_SeeHelp_Message
  442.                 WScript.Quit(ERR_GENERAL_FAILURE)
  443.             End If
  444.         
  445.             intOperation = OPER_QUERY
  446.  
  447.             If oScriptHelper.IsHelpRequested(arg) Then
  448.                 DisplayQueryHelpMessage
  449.                 WScript.Quit(ERR_OK)
  450.             End If
  451.  
  452.             aArgs = oScriptHelper.GetSwitch(arg)
  453.     End Select
  454. Next
  455.  
  456. ' Check Parameters
  457. If intOperation = 0 Then
  458.     WScript.Echo L_OperationRequired_ErrorMessage
  459.     WScript.Echo L_SeeHelp_Message
  460.     WScript.Quit(ERR_GENERAL_FAILURE)
  461. End If
  462.  
  463. ' Check if /p is specified but /u isn't. In this case, we should bail out with an error
  464. If oScriptHelper.Switches.Exists("password") And Not oScriptHelper.Switches.Exists("user") Then
  465.     WScript.Echo L_PassWithoutUser_ErrorMessage
  466.     WScript.Quit(ERR_GENERAL_FAILURE)
  467. End If
  468.  
  469. ' Check if /u is specified but /p isn't. In this case, we should ask for a password
  470. If oScriptHelper.Switches.Exists("user") And Not oScriptHelper.Switches.Exists("password") Then
  471.         strPassword = oCmdLib.GetPassword
  472. End If
  473.  
  474. ' Initializes authentication with remote machine
  475. intResult = oScriptHelper.InitAuthentication(strServer, strUser, strPassword)
  476. If intResult <> 0 Then
  477.     WScript.Quit(intResult)
  478. End If
  479.  
  480. ' Choose operation
  481. Select Case intOperation
  482.     Case OPER_START
  483.         intResult = ChangeWebSiteStatus(aArgs, SERVER_STARTED)
  484.         
  485.     Case OPER_STOP
  486.         intResult = ChangeWebSiteStatus(aArgs, SERVER_STOPPED)
  487.  
  488.     Case OPER_PAUSE
  489.         intResult = ChangeWebSiteStatus(aArgs, SERVER_PAUSED)
  490.  
  491.     Case OPER_DELETE
  492.         intResult = DeleteWebSite(aArgs)
  493.  
  494.     Case OPER_CREATE
  495.         'intResult = CreateWebSite(aArgs)
  496.         intResult = CreateWebSite(strRoot, strName, strHost, strPort, strIP, bDontStart)
  497.  
  498.     Case OPER_QUERY
  499.         intResult = QueryWebSite(aArgs)
  500.  
  501. End Select
  502.  
  503. ' Return value to command processor
  504. WScript.Quit(intResult)
  505.  
  506. '''''''''''''''''''''''''
  507. ' End Of Main Block
  508. '''''''''''''''''''''
  509.  
  510. '''''''''''''''''''''''''''
  511. ' DisplayHelpMessage
  512. '''''''''''''''''''''''''''
  513. Sub DisplayHelpMessage()
  514.     WScript.Echo L_Help_HELP_General01_Text
  515.     WScript.Echo L_Help_HELP_General01a_Text
  516.     WScript.Echo 
  517.     WScript.Echo L_Help_HELP_General02_Text
  518.     WScript.Echo L_Help_HELP_General03_Text
  519.     WScript.Echo 
  520.     WScript.Echo L_Help_HELP_General04_Text
  521.     WScript.Echo L_Help_HELP_General05_Text
  522.     WScript.Echo L_Help_HELP_General06_Text
  523.     WScript.Echo L_Help_HELP_General07_Text
  524.     WScript.Echo L_Help_HELP_General07a_Text
  525.     WScript.Echo L_Help_HELP_General08_Text
  526.     WScript.Echo L_Help_HELP_General09_Text
  527.     WScript.Echo L_Help_HELP_General10_Text
  528.     WScript.Echo L_Help_HELP_General11_Text
  529.     WScript.Echo L_Help_HELP_General11a_Text
  530.     WScript.Echo L_Help_HELP_General12_Text
  531.     WScript.Echo L_Help_HELP_General13_Text
  532.     WScript.Echo L_Help_HELP_General14_Text
  533.     WScript.Echo L_Help_HELP_General15_Text
  534.     WScript.Echo L_Help_HELP_General18_Text
  535.     WScript.Echo L_Help_HELP_General19_Text
  536.     WScript.Echo L_Help_HELP_General19a_Text
  537.     WScript.Echo L_Help_HELP_General20_Text
  538.     WScript.Echo L_Help_HELP_General21_Text
  539.     WScript.Echo 
  540.     WScript.Echo L_Help_HELP_General22_Text
  541.     WScript.Echo 
  542.     WScript.Echo L_Help_HELP_General23_Text
  543.     WScript.Echo L_Help_HELP_General24_Text
  544.     WScript.Echo L_Help_HELP_General25_Text
  545.     WScript.Echo L_Help_HELP_General27_Text
  546.     WScript.Echo L_Help_HELP_General28_Text
  547.     WScript.Echo L_Help_HELP_General29_Text
  548. End Sub
  549.  
  550. Sub DisplayStartHelpMessage()
  551.     WScript.Echo L_Help_HELP_Start01_Text
  552.     WScript.Echo 
  553.     WScript.Echo L_Help_HELP_Start02_Text
  554.     WScript.Echo L_Help_HELP_Start02p1_Text
  555.     WScript.Echo 
  556.     WScript.Echo L_Help_HELP_Status03_Text
  557.     WScript.Echo 
  558.     WScript.Echo L_Help_HELP_General06_Text
  559.     WScript.Echo L_Help_HELP_General07_Text
  560.     WScript.Echo L_Help_HELP_General07a_Text
  561.     WScript.Echo L_Help_HELP_General08_Text
  562.     WScript.Echo L_Help_HELP_General09_Text
  563.     WScript.Echo L_Help_HELP_General10_Text
  564.     WScript.Echo L_Help_HELP_Status09_Text
  565.     WScript.Echo L_Help_HELP_Status09p1_Text
  566.     WScript.Echo 
  567.     WScript.Echo 
  568.     WScript.Echo L_Help_HELP_Status10_Text
  569.     WScript.Echo 
  570.     WScript.Echo L_Help_HELP_Start11_Text
  571.     WScript.Echo L_Help_HELP_Start12_Text
  572.     WScript.Echo L_Help_HELP_Start13_Text
  573.     WScript.Echo L_Help_HELP_Start14_Text
  574. End Sub
  575.  
  576. Sub DisplayStopHelpMessage()
  577.     WScript.Echo L_Help_HELP_Stop01_Text
  578.     WScript.Echo 
  579.     WScript.Echo L_Help_HELP_Stop02_Text
  580.     WScript.Echo L_Help_HELP_Stop02p1_Text
  581.     WScript.Echo 
  582.     WScript.Echo L_Help_HELP_Status03_Text
  583.     WScript.Echo 
  584.     WScript.Echo L_Help_HELP_General06_Text
  585.     WScript.Echo L_Help_HELP_General07_Text
  586.     WScript.Echo L_Help_HELP_General07a_Text
  587.     WScript.Echo L_Help_HELP_General08_Text
  588.     WScript.Echo L_Help_HELP_General09_Text
  589.     WScript.Echo L_Help_HELP_General10_Text
  590.     WScript.Echo L_Help_HELP_Status09_Text
  591.     WScript.Echo L_Help_HELP_Status09p1_Text
  592.     WScript.Echo 
  593.     WScript.Echo 
  594.     WScript.Echo L_Help_HELP_Status10_Text
  595.     WScript.Echo 
  596.     WScript.Echo L_Help_HELP_Stop11_Text
  597.     WScript.Echo L_Help_HELP_Stop12_Text
  598.     WScript.Echo L_Help_HELP_Stop13_Text
  599.     WScript.Echo L_Help_HELP_Stop14_Text
  600. End Sub
  601.  
  602. Sub DisplayPauseHelpMessage()
  603.     WScript.Echo L_Help_HELP_Pause01_Text
  604.     WScript.Echo 
  605.     WScript.Echo L_Help_HELP_Pause02_Text
  606.     WScript.Echo L_Help_HELP_Pause02p1_Text
  607.     WScript.Echo 
  608.     WScript.Echo L_Help_HELP_Status03_Text
  609.     WScript.Echo 
  610.     WScript.Echo L_Help_HELP_General06_Text
  611.     WScript.Echo L_Help_HELP_General07_Text
  612.     WScript.Echo L_Help_HELP_General07a_Text
  613.     WScript.Echo L_Help_HELP_General08_Text
  614.     WScript.Echo L_Help_HELP_General09_Text
  615.     WScript.Echo L_Help_HELP_General10_Text
  616.     WScript.Echo L_Help_HELP_Status09_Text
  617.     WScript.Echo L_Help_HELP_Status09p1_Text
  618.     WScript.Echo 
  619.     WScript.Echo 
  620.     WScript.Echo L_Help_HELP_Status10_Text
  621.     WScript.Echo 
  622.     WScript.Echo L_Help_HELP_Pause11_Text
  623.     WScript.Echo L_Help_HELP_Pause12_Text
  624.     WScript.Echo L_Help_HELP_Pause13_Text
  625.     WScript.Echo L_Help_HELP_Pause14_Text
  626. End Sub
  627.  
  628. Sub DisplayDeleteHelpMessage()
  629.     WScript.Echo L_Help_HELP_Delete01_Text
  630.     WScript.Echo L_Help_HELP_Delete01p1_Text
  631.     WScript.Echo 
  632.     WScript.Echo L_Help_HELP_Delete02_Text
  633.     WScript.Echo L_Help_HELP_Delete02p1_Text
  634.     WScript.Echo 
  635.     WScript.Echo L_Help_HELP_Status03_Text
  636.     WScript.Echo 
  637.     WScript.Echo L_Help_HELP_General06_Text
  638.     WScript.Echo L_Help_HELP_General07_Text
  639.     WScript.Echo L_Help_HELP_General07a_Text
  640.     WScript.Echo L_Help_HELP_General08_Text
  641.     WScript.Echo L_Help_HELP_General09_Text
  642.     WScript.Echo L_Help_HELP_General10_Text
  643.     WScript.Echo L_Help_HELP_Status09_Text
  644.     WScript.Echo L_Help_HELP_Status09p1_Text
  645.     WScript.Echo 
  646.     WScript.Echo 
  647.     WScript.Echo L_Help_HELP_Status10_Text
  648.     WScript.Echo 
  649.     WScript.Echo L_Help_HELP_Delete11_Text
  650.     WScript.Echo L_Help_HELP_Delete12_Text
  651.     WScript.Echo L_Help_HELP_Delete13_Text
  652.     WScript.Echo L_Help_HELP_Delete14_Text
  653. End Sub
  654.  
  655. Sub DisplayCreateHelpMessage()
  656.     WScript.Echo L_Help_HELP_Create01_Text
  657.     WScript.Echo 
  658.     WScript.Echo L_Help_HELP_Create02_Text
  659.     WScript.Echo L_Help_HELP_Create02p1_Text
  660.     WScript.Echo L_Help_HELP_Create02p2_Text
  661.     WScript.Echo 
  662.     WScript.Echo L_Help_HELP_Status03_Text
  663.     WScript.Echo 
  664.     WScript.Echo L_Help_HELP_General06_Text
  665.     WScript.Echo L_Help_HELP_General07_Text
  666.     WScript.Echo L_Help_HELP_General07a_Text
  667.     WScript.Echo L_Help_HELP_General08_Text
  668.     WScript.Echo L_Help_HELP_General09_Text
  669.     WScript.Echo L_Help_HELP_General10_Text
  670.     WScript.Echo L_Help_HELP_Create09_Text
  671.     WScript.Echo L_Help_HELP_Create09p1_Text
  672.     WScript.Echo L_Help_HELP_Create09p2_Text
  673.     WScript.Echo L_Help_HELP_Create10_Text
  674.     WScript.Echo L_Help_HELP_Create10p1_Text
  675.     WScript.Echo L_Help_HELP_Create11_Text
  676.     WScript.Echo L_Help_HELP_Create11p1_Text
  677.     WScript.Echo L_Help_HELP_Create11p2_Text
  678.     WScript.Echo L_Help_HELP_Create12_Text
  679.     WScript.Echo L_Help_HELP_Create12p1_Text
  680.     WScript.Echo L_Help_HELP_Create13_Text
  681.     WScript.Echo L_Help_HELP_Create13p1_Text
  682.     WScript.Echo L_Help_HELP_Create15_Text
  683.     WScript.Echo 
  684.     WScript.Echo L_Help_HELP_Status10_Text
  685.     WScript.Echo 
  686.     WScript.Echo L_Help_HELP_Create22_Text
  687.     WScript.Echo L_Help_HELP_Create23_Text
  688.     WScript.Echo L_Help_HELP_Create23p1_Text
  689.     WScript.Echo L_Help_HELP_Create24_Text
  690.     WScript.Echo L_Help_HELP_Create24p1_Text
  691. End Sub
  692.  
  693. Sub DisplayQueryHelpMessage()
  694.     WScript.Echo L_Help_HELP_Query01_Text
  695.     WScript.Echo 
  696.     WScript.Echo L_Help_HELP_Query02_Text
  697.     WScript.Echo L_Help_HELP_Query02p1_Text
  698.     WScript.Echo 
  699.     WScript.Echo L_Help_HELP_Status03_Text
  700.     WScript.Echo 
  701.     WScript.Echo L_Help_HELP_General06_Text
  702.     WScript.Echo L_Help_HELP_General07_Text
  703.     WScript.Echo L_Help_HELP_General07a_Text
  704.     WScript.Echo L_Help_HELP_General08_Text
  705.     WScript.Echo L_Help_HELP_General09_Text
  706.     WScript.Echo L_Help_HELP_General10_Text
  707.     WScript.Echo L_Help_HELP_Status09_Text
  708.     WScript.Echo L_Help_HELP_Status09p1_Text
  709.     WScript.Echo 
  710.     WScript.Echo 
  711.     WScript.Echo L_Help_HELP_Status10_Text
  712.     WScript.Echo 
  713.     WScript.Echo L_Help_HELP_Query11_Text
  714.     WScript.Echo L_Help_HELP_Query12_Text
  715.     WScript.Echo L_Help_HELP_Query13_Text
  716.     WScript.Echo L_Help_HELP_Query14_Text
  717.     WScript.Echo L_Help_HELP_Query15_Text
  718. End Sub
  719.  
  720.  
  721. '''''''''''''''''''''''''''
  722. ' ChangeWebSiteStatus
  723. '
  724. ' Try to change the status of a site 
  725. ' to the one specified 
  726. '''''''''''''''''''''''''''
  727. Function ChangeWebSiteStatus(aArgs, newStatus)
  728.     Dim Server, strSiteName
  729.     Dim intResult, i, intNewStatus
  730.     Dim aSites
  731.     Dim providerObj, ServiceObj
  732.     Dim bNonFatalError
  733.  
  734.     On Error Resume Next
  735.  
  736.     bNonFatalError = False
  737.  
  738.     oScriptHelper.WMIConnect
  739.     If Err.Number Then
  740.         WScript.Echo L_WMIConnect_ErrorMessage
  741.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  742.         ChangeWebSiteStatus = Err.Number
  743.         Exit Function
  744.     End If
  745.     
  746.     Set providerObj = oScriptHelper.ProviderObj
  747.     intResult = 0
  748.  
  749.     ' Quick check to see if we have permission
  750.     Set ServiceObj = providerObj.Get("IIsWebService='W3SVC'")
  751.     If Err.Number Then
  752.         Select Case Err.Number
  753.             Case &H80070005
  754.                 WScript.Echo L_Admin_ErrorMessage
  755.                 WScript.Echo L_Admin2_ErrorMessage
  756.  
  757.             Case Else
  758.                 WScript.Echo Err.Description
  759.         End Select
  760.         
  761.         ChangeWebSiteStatus = Err.Number
  762.         Exit Function
  763.     End If
  764.  
  765.     aSites = oScriptHelper.FindSite("Web", aArgs)
  766.     If IsArray(aSites) Then
  767.         If UBound(aSites) = -1 Then
  768.             WScript.Echo L_SitesNotFound_ErrorMessage
  769.             intResult = ERR_GENERAL_FAILURE
  770.         End If
  771.     Else
  772.         ' Got duplicate sites. We should quit.
  773.         ChangeWebSiteStatus = intResult
  774.         Exit Function
  775.     End If
  776.     
  777.     For i = LBound(aSites) to UBound(aSites)
  778.         strSiteName = aSites(i)
  779.  
  780.         bNonFatalError = False
  781.  
  782.         ' Grab site state before trying to start it
  783.         Set Server = providerObj.Get("IIsWebServer='" & strSiteName & "'")
  784.         If (Err.Number <> 0) Then
  785.             WScript.Echo L_GetWebServer_ErrorMessage
  786.             oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  787.             intResult = Err.Number
  788.         End If
  789.  
  790.         If (Server.ServerState = newStatus) Then
  791.             oCmdLib.vbPrintf L_IsAlready_Message, Array(strSiteName, UCase(SiteStatus(newStatus)))
  792.         Else 
  793.             If (Server.ServerState = SERVER_STARTING or Server.ServerState = SERVER_STOPPING or _
  794.                 Server.ServerState = SERVER_PAUSING or Server.ServerState = SERVER_CONTINUING) Then
  795.  
  796.                 WScript.Echo L_CannotControl_ErrorMessage
  797.                 intResult = ERR_GENERAL_FAILURE
  798.             Else
  799.  
  800.                 Select Case newStatus
  801.                 Case SERVER_STARTED
  802.                     If (Server.ServerState = SERVER_STOPPED) Then
  803.                         intNewStatus = SERVER_STARTED
  804.                         Server.Start
  805.                     Else 
  806.                         If (Server.ServerState = SERVER_PAUSED) Then
  807.                             intNewStatus = SERVER_CONTINUING
  808.                             Server.Continue
  809.                         Else
  810.                             oCmdLib.vbPrintf L_CannotStart_Message, Array(strSiteName)
  811.                             oCmdLib.vbPrintf L_CannotStart2_Message, Array(strSiteName, SiteStatus(Server.ServerState))
  812.                             bNonFatalError = True
  813.                         End If
  814.                     End If
  815.  
  816.                 Case SERVER_STOPPED
  817.                     If (Server.ServerState = SERVER_STARTED) Then
  818.                         intNewStatus = SERVER_STOPPED
  819.                         Server.Stop
  820.                     Else
  821.                         oCmdLib.vbPrintf L_CannotStop_Message, Array(strSiteName)
  822.                         oCmdLib.vbPrintf L_CannotStop2_Message, Array(strSiteName, SiteStatus(Server.ServerState))
  823.                         bNonFatalError = True
  824.                     End If
  825.  
  826.                 Case SERVER_PAUSED
  827.                     If (Server.ServerState = SERVER_STARTED) Then
  828.                         intNewStatus = SERVER_PAUSED
  829.                         Server.Pause
  830.                     Else
  831.                         oCmdLib.vbPrintf L_CannotPause_Message, Array(strSiteName)
  832.                         oCmdLib.vbPrintf L_CannotPause2_Message, Array(strSiteName, SiteStatus(Server.ServerState))
  833.                         bNonFatalError = True
  834.                     End If
  835.  
  836.                 Case Else
  837.                     WScript.Echo L_UnexpectedState_ErrorMessage
  838.                     WScript.Quit(ERR_GENERAL_FAILURE)
  839.  
  840.                 End Select
  841.  
  842.                 ' Error checking
  843.                 If (Err.Number <> 0) Then
  844.                     oCmdLib.vbPrintf L_FailChange_ErrorMessage, Array(strSite)
  845.                     oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  846.                     intResult = Err.Number
  847.                 Else
  848.                     If (bNonFatalError = False) Then
  849.                         oCmdLib.vbPrintf L_HasBeen_Message, Array(strSiteName, UCase(SiteStatus(intNewStatus)))
  850.                     End If
  851.                 End If
  852.             End If    
  853.         End If
  854.  
  855.     Next
  856.  
  857.     Set Server = Nothing
  858.  
  859.     ChangeWebSiteStatus = intResult
  860. End Function
  861.  
  862.  
  863. '''''''''''''''''''''''''''
  864. ' DeleteWebSite
  865. '''''''''''''''''''''''''''
  866. Function DeleteWebSite(aArgs)
  867.     Dim strSiteName
  868.     Dim RootVDirObj, WebServerObj
  869.     Dim aSites
  870.     Dim providerObj, ServiceObj
  871.     
  872.     On Error Resume Next
  873.  
  874.     oScriptHelper.WMIConnect
  875.     If Err.Number Then
  876.         WScript.Echo L_WMIConnect_ErrorMessage
  877.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  878.         DeleteWebSite = Err.Number
  879.         Exit Function
  880.     End If
  881.  
  882.     Set providerObj = oScriptHelper.ProviderObj
  883.  
  884.     ' Quick check to see if we have permission
  885.     Set ServiceObj = providerObj.Get("IIsWebService='W3SVC'")
  886.     If Err.Number Then
  887.         Select Case Err.Number
  888.             Case &H80070005
  889.                 WScript.Echo L_Admin_ErrorMessage
  890.                 WScript.Echo L_Admin2_ErrorMessage
  891.  
  892.             Case Else
  893.                 WScript.Echo Err.Description
  894.         End Select
  895.         
  896.         DeleteWebSite = Err.Number
  897.         Exit Function
  898.     End If
  899.  
  900.     aSites = oScriptHelper.FindSite("Web", aArgs)
  901.     If IsArray(aSites) Then
  902.         If UBound(aSites) = -1 Then
  903.             WScript.Echo L_SitesNotFound_ErrorMessage
  904.             intResult = ERR_GENERAL_FAILURE
  905.         End If
  906.     Else
  907.         ' Got duplicate sites. We should quit.
  908.         ChangeWebSiteStatus = intResult
  909.         Exit Function
  910.     End If
  911.     
  912.     For Each strSiteName in aSites
  913.         ' First delete application in this site
  914.         Set RootVDirObj = providerObj.Get("IIsWebVirtualDir='" & strSiteName & "/ROOT'")
  915.         If (Err.Number <> 0) Then
  916.             oCmdLib.vbPrintf L_GetRoot_ErrorMessage, Array(strSiteName)
  917.             oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  918.             DeleteWebSite = Err.Number
  919.             Exit Function
  920.         End If
  921.         
  922.         RootVDirObj.AppDelete(True)
  923.         If (Err.Number <> 0) Then
  924.             oCmdLib.vbPrintf L_RecursiveDel_ErrorMessage, Array(strSiteName)
  925.             oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  926.             DeleteWebSite = Err.Number
  927.             Exit Function
  928.         End If
  929.         
  930.         ' Next, stop and delete the web site itself
  931.         Set WebServerObj = providerObj.Get("IIsWebServer='" & strSiteName & "'")
  932.         If (Err.Number <> 0) Then
  933.             oCmdLib.vbPrintf L_SiteGet_ErrorMessage, Array(strSiteName)
  934.             oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  935.             DeleteWebSite = Err.Number
  936.             Exit Function
  937.         End If
  938.         
  939.         WebServerObj.Stop
  940.         If (Err.Number <> 0) Then
  941.             oCmdLib.vbPrintf L_Stop_ErrorMessage, Array(strSiteName)
  942.             oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  943.             DeleteWebSite = Err.Number
  944.             Exit Function
  945.         End If
  946.         
  947.         WebServerObj.Delete_
  948.         If (Err.Number <> 0) Then
  949.             oCmdLib.vbPrintf L_SiteDel_ErrorMessage, Array(strSiteName)
  950.             oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  951.             DeleteWebSite = Err.Number
  952.             Exit Function
  953.         End If
  954.         
  955.         oCmdLib.vbPrintf L_HasBeen_Message, Array(strSiteName, L_Deleted_Text)
  956.     Next
  957.  
  958.     DeleteWebSite = ERR_OK
  959. End Function
  960.  
  961.  
  962. '''''''''''''''''''''''''''
  963. ' CreateWebSite
  964. '''''''''''''''''''''''''''
  965. Function CreateWebSite(strRoot, strName, strHost, strPort, strIP, bDontStart)
  966.     Dim strSitePath
  967.     Dim strSiteObjPath
  968.     Dim Bindings
  969.     Dim objPath, serviceObj
  970.     Dim serverObj, vdirObj
  971.     Dim strStatus
  972.     Dim providerObj
  973.     
  974.     On Error Resume Next
  975.     
  976.     ' Default port
  977.     If (strPort = "") Then strPort = "80"
  978.  
  979.     ' Verify port number
  980.     If Not oScriptHelper.IsValidPortNumber(strPort) Then
  981.         WScript.Echo L_InvalidPort_ErrorMessage
  982.         CreateWebSite = ERR_GENERAL_FAILURE
  983.         Exit Function
  984.     End If
  985.     
  986.     ' Verify IP Address
  987.     If strIP <> "" Then
  988.         If Not oScriptHelper.IsValidIPAddress(strIP) Then
  989.             WScript.Echo L_InvalidIP_ErrorMessage
  990.             WScript.Echo L_InvalidIP2_ErrorMessage
  991.             CreateWebSite = ERR_GENERAL_FAILURE
  992.             Exit Function
  993.         End If
  994.     End If
  995.     
  996.     ' Create physical directory
  997.     oScriptHelper.CreateFSDir strRoot
  998.     If Err.Number Then
  999.         Select Case Err.Number
  1000.             Case &H8007000C
  1001.                 WScript.Echo L_DirFormat_ErrorMessage
  1002.                 WScript.Echo L_DirFormat2_ErrorMessage
  1003.                 WScript.Echo L_SeeCreateHelp_Message
  1004.                 CreateWebSite = Err.Number
  1005.                 Exit Function
  1006.             
  1007.             Case &H8007000F
  1008.                 WScript.Echo L_MapDrive_ErrorMessage
  1009.                 CreateWebSite = Err.Number
  1010.                 Exit Function
  1011.     
  1012.             Case Else
  1013.                 WScript.Echo L_CannotCreateDir_ErrorMessage
  1014.                 oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  1015.                 CreateWebSite = Err.Number
  1016.                 Exit Function
  1017.         End Select
  1018.     End If
  1019.  
  1020.     ' Time to connect to the IIS namespace
  1021.     oScriptHelper.WMIConnect
  1022.     If Err.Number Then
  1023.         WScript.Echo L_WMIConnect_ErrorMessage
  1024.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  1025.         CreateWebSite = Err.Number
  1026.         Exit Function
  1027.     End If
  1028.  
  1029.     Set providerObj = oScriptHelper.ProviderObj
  1030.     
  1031.     ' Build binding object
  1032.     Bindings = Array(0)
  1033.     Set Bindings(0) = providerObj.get("ServerBinding").SpawnInstance_()
  1034.     Bindings(0).IP = strIP
  1035.     Bindings(0).Port = strPort
  1036.     Bindings(0).Hostname = strHost
  1037.  
  1038.     Set serviceObj = providerObj.Get("IIsWebService='W3SVC'")
  1039.     If Err.Number Then
  1040.         Select Case Err.Number
  1041.             Case &H80070005
  1042.                 WScript.Echo L_Admin_ErrorMessage
  1043.                 WScript.Echo L_Admin2_ErrorMessage
  1044.  
  1045.             Case Else
  1046.                 WScript.Echo Err.Description
  1047.         End Select
  1048.         
  1049.         CreateWebSite = Err.Number
  1050.         Exit Function
  1051.     End If
  1052.  
  1053.     strSiteObjPath = serviceObj.CreateNewSite(strName, Bindings, strRoot)
  1054.     
  1055.     If Err Then
  1056.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  1057.         CreateWebSite = Err.Number
  1058.         Exit Function        
  1059.     End If
  1060.     
  1061.     ' Parse site ID out of WMI object path
  1062.     Set objPath = CreateObject("WbemScripting.SWbemObjectPath")
  1063.     objPath.Path = strSiteObjPath
  1064.     strSitePath = objPath.Keys.Item("")
  1065.    
  1066.     ' Set web virtual directory properties
  1067.     Set vdirObj = providerObj.Get("IIsWebVirtualDirSetting='" & strSitePath & "/ROOT'")
  1068.     vdirObj.AuthFlags = 5 ' AuthNTLM + AuthAnonymous
  1069.     vdirObj.EnableDefaultDoc = True
  1070.     vdirObj.DirBrowseFlags = &H4000003E ' date, time, size, extension, longdate
  1071.     vdirObj.AccessFlags = 513 ' read, script
  1072.     vdirObj.Put_()
  1073.     If Err Then
  1074.         WScript.Echo L_VDirPut_ErrorMessage
  1075.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  1076.         providerObj.Delete(strSiteObjPath)
  1077.         CreateWebSite = Err.Number
  1078.         Exit Function        
  1079.     End If
  1080.     
  1081.     ' Site should be stopped - CreateNewSite stops it by default
  1082.     Set serverObj = providerObj.Get("IIsWebServer='" & strSitePath & "'")
  1083.  
  1084.     ' Should we start the site?
  1085.     If Not bDontStart Then
  1086.         serverObj.Start
  1087.         ' If we cannot start the server, check for error stating the port is already in use
  1088.         If Err.Number = &H80070034 Or Err.Number = &H80070020 Then
  1089.             strStatus = UCase(SiteStatus(4)) & " " & L_BindingConflict_ErrorMessage
  1090.         Else
  1091.             strStatus = UCase(SiteStatus(2))
  1092.         End If
  1093.     Else
  1094.         strStatus = UCase(SiteStatus(4))
  1095.     End If
  1096.  
  1097.     If (strServer = ".") Then 
  1098.         strServer = oScriptHelper.GetEnvironmentVar("%COMPUTERNAME%")
  1099.     End If
  1100.  
  1101.     If (strIP = "") Then strIP = L_AllUnassigned_Text
  1102.     If (strHost = "") Then strHost = L_NotSpecified_Text
  1103.  
  1104.     ' Post summary
  1105.     WScript.Echo L_Server_Text & Space(14 - Len(L_Server_Text)) & "= " & UCase(strServer)
  1106.     WScript.Echo L_SiteName_Text & Space(14 - Len(L_SiteName_Text)) & "= " & strName
  1107.     WScript.Echo L_MetabasePath_Message & Space(14 - Len(L_MetabasePath_Message)) & "= " & strSitePath
  1108.     WScript.Echo L_IP_Text & Space(14 - Len(L_IP_Text)) & "= " & strIP
  1109.     WScript.Echo L_Host_Text & Space(14 - Len(L_Host_Text)) & "= " & strHost
  1110.     WScript.Echo L_Port_Text & Space(14 - Len(L_Port_Text)) & "= " & strPort
  1111.     WScript.Echo L_Root_Text & Space(14 - Len(L_Root_Text)) & "= " & strRoot
  1112.        WScript.Echo L_Status_Text& Space(14 - Len(L_Status_Text)) & "= " & strStatus
  1113.     
  1114.     CreateWebSite = intResult
  1115. End Function
  1116.  
  1117.  
  1118. '''''''''''''''''''''''''''
  1119. ' QueryWebSite
  1120. '''''''''''''''''''''''''''
  1121. Function QueryWebSite(aArgs)
  1122.     Dim Servers, Server, strQuery
  1123.     Dim ServerObj, ServiceObj
  1124.     Dim i, intResult, firstLen, secLen, thirdLen, fourthLen
  1125.     Dim bindings, binding
  1126.     Dim line, strIP, strPort, strHost, strState
  1127.     Dim providerObj
  1128.     Dim bFirstIteration
  1129.     
  1130.     On Error Resume Next
  1131.  
  1132.     oScriptHelper.WMIConnect
  1133.     If Err.Number Then
  1134.         WScript.Echo L_WMIConnect_ErrorMessage
  1135.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  1136.         QueryWebSiteStatus = Err.Number
  1137.         Exit Function
  1138.     End If
  1139.  
  1140.     Set providerObj = oScriptHelper.ProviderObj
  1141.     intResult = 0
  1142.  
  1143.     ' Quick check to see if we have permission
  1144.     Set ServiceObj = providerObj.Get("IIsWebService='W3SVC'")
  1145.     If Err.Number Then
  1146.         Select Case Err.Number
  1147.             Case &H80070005
  1148.                 WScript.Echo L_Admin_ErrorMessage
  1149.                 WScript.Echo L_Admin2_ErrorMessage
  1150.  
  1151.             Case Else
  1152.                 WScript.Echo Err.Description
  1153.         End Select
  1154.         
  1155.         QueryWebSite = Err.Number
  1156.         Exit Function
  1157.     End If
  1158.  
  1159.     If (UBound(aArgs) = -1) Then
  1160.         strQuery = "select Name, ServerComment, ServerBindings from IIsWebServerSetting"
  1161.     Else
  1162.         strQuery = "select Name, ServerComment, ServerBindings from IIsWebServerSetting where "
  1163.         For i = LBound(aArgs) to UBound(aArgs)
  1164.             strQuery = strQuery & "(Name='" & aArgs(i) & "' or ServerComment='" & aArgs(i) & "')"
  1165.             If (i <> UBound(aArgs)) Then
  1166.                 strQuery = strQuery & " or "
  1167.             End If
  1168.         Next
  1169.     End If
  1170.     
  1171.     ' Semi-sync query. (flags = ForwardOnly Or ReturnImediately = &H30)
  1172.     Set Servers = providerObj.ExecQuery(strQuery, , &H30)
  1173.     If (Err.Number <> 0) Then
  1174.         WScript.Echo L_Query_ErrorMessage
  1175.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  1176.         WScript.Quit(Err.Number)
  1177.     End If
  1178.  
  1179.     bFirstIteration = True
  1180.     For Each Server in Servers
  1181.         bindings = Server.ServerBindings
  1182.  
  1183.         If bFirstIteration Then
  1184.             WScript.Echo L_SiteName_Text & " (" & L_MetabasePath_Message & ")" & _
  1185.                 Space(40 - Len(L_SiteName_Text & L_MetabasePath_Message) + 3) & _
  1186.                 L_Status_Text & Space(2) & L_IP_Text & Space(14) & L_Port_Text & Space(2) & L_Host_Text
  1187.             WScript.Echo "=============================================================================="
  1188.         End If
  1189.         
  1190.         ' Get server status from the element instance
  1191.         Set ServerObj = providerObj.Get("IIsWebServer='" & Server.Name & "'")
  1192.         strState = UCase(SiteStatus(ServerObj.ServerState))
  1193.         
  1194.         If (IsArray(bindings)) Then
  1195.             For i = LBound(bindings) to UBound(bindings)
  1196.                 If (bindings(i).IP = "") Then
  1197.                     strIP = L_All_Text
  1198.                 Else
  1199.                     strIP = bindings(i).IP
  1200.                 End If
  1201.     
  1202.                 strPort = bindings(i).Port
  1203.     
  1204.                 If (bindings(i).Hostname = "") Then
  1205.                     strHost = L_NA_Text
  1206.                 Else
  1207.                     strHost = bindings(i).Hostname
  1208.                 End If
  1209.     
  1210.                 ' If this is the first binding list, print server comment and server name        
  1211.                 If (i = LBound(bindings)) Then
  1212.  
  1213.                     firstLen  = 40 - Len(Server.ServerComment & Server.Name) + 3
  1214.                     secLen    =  8 - Len(strState)
  1215.                     thirdLen  = 16 - Len(strIP)
  1216.                     fourthLen =  6 - Len(strPort)
  1217.  
  1218.                     If (firstLen < 1) Then
  1219.                         firstLen = 1
  1220.                     End If
  1221.  
  1222.                     If (secLen < 1) Then
  1223.                         secLen = 1
  1224.                     End If
  1225.  
  1226.                     If (thirdLen < 1) Then
  1227.                         thirdLen = 1
  1228.                     End If
  1229.  
  1230.                     If (fourthLen < 1) Then
  1231.                         fourthLen = 1
  1232.                     End If
  1233.  
  1234.                     line = Server.ServerComment & " (" & Server.Name & ")" & _
  1235.                         Space(firstLen) & strState & _
  1236.                         Space(secLen) & strIP & Space(thirdLen) & strPort & _
  1237.                         Space(fourthLen) & strHost
  1238.                 Else
  1239.                     line = Space(54) & strIP & Space(thirdLen) & strPort & Space(fourthLen) & strHost
  1240.                 End If
  1241.  
  1242.                 WScript.Echo line
  1243.             Next
  1244.         End If
  1245.         
  1246.         bFirstIteration = False
  1247.     Next
  1248.     
  1249.     If bFirstIteration Then
  1250.         WScript.Echo L_SitesNotFound_ErrorMessage
  1251.     End If
  1252.         
  1253. End Function
  1254.